import {ref,watch} from 'vue';
function useDebounce(refValue,delay=1000){
    const debouncedValue = ref(refValue.value);
    let timer;
    //如果观察到refValue发生了变化，会执行回调，并传递最新的值
    watch(refValue,(newVal)=>{
        if(timer)clearTimeout(timer);
        //开启一个新的定时器，
        timer = setTimeout(()=>{
            debouncedValue.value = newVal;
        },delay);
    });
    return debouncedValue;
}
export default useDebounce;